{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox-title">
        <h5>编辑热门城市</h5>
    </div>
    <div class="ibox-content layui-form">
        <div class="layui-row layui-col-space10 layui-form-item ">
            <input type="hidden" name="id" value="{$hot.hot_id}">
            <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                <label class="layui-form-label">城市：</label>
                <div class="layui-input-block">
                    <select name="city" lay-search="" lay-verify="required" lay-filter="city">
                        <option  value="">选择城市</option>
                        {foreach $data as $vo}
                        <option value="{$vo.district_id}"{eq name="$hot.hot_city" value="$vo.district_id"}selected{/eq}>{$vo.district}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                <label class="layui-form-label">区/县：</label>
                <div class="layui-input-block">
                    <select name="qu" lay-search="" lay-verify="required">
                        <option  value="">选择区/县</option>
                        {foreach $qu as $vo}
                        <option value="{$vo.district_id}"{eq name="$hot.hot_qu" value="$vo.district_id"}selected{/eq}  {in name="$vo.district_id" value="$have"}disabled{/in}>{$vo.district}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
                    </button>
                    <button class="layui-btn layui-btn-primary" onclick="history.go(-1)">返回</button>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    layui.use(['form'], function() {
        var form = layui.form;

        form.on('select(city)', function(data){
            $.ajax({
                url:"{:url('getQuData')}",
                type:'post',
                dataType:'json',
                data:{id:data.value},
                success:function(res){
                    var html = '<option  value="">选择区/县</option>'
                        ,dis = ''
                    if(res.msg.length > 0){
                        $.each(res.msg,function (index,item) {
                            if(res.data.length > 0 && item.district_id != {$hot.hot_qu}){
                                dis = res.data.indexOf(item.district_id) > -1 ? 'disabled' : '';
                            }
                            html += '<option  value="'+item.district_id+'" '+dis+'>'+item.district+'</option>'
                        });
                    }
                    $("select[name=qu]").empty().append(html);
                    form.render();
                }
            })
        });

        form.on('submit(component-form-element)', function (data) {
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('hotEdit')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        wk.success(res.msg,"{:url('hot/index')}")
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });
    });
</script>
</body>
</html>